package com.blog.blogservice.api.controller.v1;

import com.blog.blogservice.domain.entity.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.blog.blogservice.app.service.BarrageService;
import com.blog.blogservice.domain.entity.Barrage;

import java.util.List;

/**
 * 弹幕表(Barrage)表控制层
 *
 * @author guanglin.ma
 * @since 2024-03-02 23:25:21
 */

@RestController("barrageController.v1")
@RequestMapping("/v1/{organizationId}/barrages")
public class BarrageController{


    @Autowired
    private BarrageService barrageService;

//    弹幕表列表
    @GetMapping
    public ResponseEntity<Page<Barrage>> list(Barrage barrage, @PathVariable Long organizationId, @SortDefault(value = Barrage.FIELD_BARRAGE_ID,
            direction = Sort.Direction.DESC) PageRequest pageRequest) {
        Page<Barrage> list = barrageService.selectList(pageRequest, barrage);
        return Results.success(list);
    }

//    弹幕表明细
    @GetMapping("/{barrageId}")
    public ResponseEntity<Barrage> detail(@PathVariable Long barrageId) {
        return null;
    }

//    创建或更新弹幕表
    @PostMapping
    public ResponseEntity<List<Barrage>> save(@PathVariable Long organizationId, @RequestBody List<Barrage> barrages) {
        barrageService.saveData(barrages);
        return Results.success(barrages);
    }

//    删除弹幕表
    @DeleteMapping
    public ResponseEntity<?> remove(@RequestBody List<Barrage> barrages) {

        return Results.success();
    }

}

